package com.jf.ai.etl.reader;

import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonMetadataGenerator;
import org.springframework.ai.reader.JsonReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-07-19
 * Time:16:45
 */
@Component
public class JfJsonReader {
    private final Resource resource;

    public JfJsonReader(@Value("classpath:bike.json") Resource resource) {
        this.resource = resource;
    }
    public List<Document> loadJsonAsDocuments() {
        JsonReader jsonReader = new JsonReader(this.resource, jsonMap -> {
            Map<String, Object> map = new HashMap<>();
            map.put("brand", jsonMap.get("brand"));
            return map;
        },"description");
        return jsonReader.get();
    }
}
